<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>主页</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/top.css">
    <script src="/js/boom.js"></script>
    <style>
        .card {
            margin-top: 1rem;
        }
        video{
          position: fixed;
          right:0;
          bottom: 0;
          min-width: 100%;
          min-height: 100%;
          width: auto;
          height: auto;
          z-index: -9999;
          /*灰色调*/
          /*-webkit-filter:grayscale(100%)*/
        }
        .card{
            background-color:rgba(44, 18, 18, 0);
        }
        
    </style>
</head>

<body>

    <div id="timer" style="color: ghostwhite; margin-left: 35rem;"></div>

    <!-- 视频 播放 透明 -->
    <video id="v1" autoplay muted loop style="width: 100%">
        <source  src="/videos/Spirited Away Train recreated in Unity 3D.mp4">
    </video>
    <div class="container"> 
        <div class="row">
            <div class="col-sm"></div>
            <div class="col-sm">
                <div class="card" style="width: 50rem;">
                    <div class="card-header">
                        <div class="row">
                           
                            <div class="col-sm-4 d-flex justify-content-start">
                                <button type="button" class="btn btn-secondary btn-sm" data-toggle="modal"
                                    data-target="#saysomething">发表说说</button>
                            </div>
                            <div class="col-sm-4 d-flex justify-content-center">
                                <p>当前用户：{{username}}</p>
                            </div>
                            <div class="col-sm-4 d-flex justify-content-end"><button type="button"
                                    class="btn btn-secondary btn-sm" onclick="logout()">注销</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <div class="col-sm">

            </div>
        </div>

        <div class="row">
            <div class="col-sm">
            </div>
            <!-- 评论 谁对谁 说 -->
            <div class="col-sm" id="saysayMsg">
                {% for msg in msgs %}
                <div class="card border-primary shadow" style="width: 50rem;">
                    <div class="card-header">
                        <div class="row">
                            <div class="col-sm-10">{{msg.content}}</div>
                            <div class="col-sm-2"><button type="button" class="btn btn-secondary btn-sm"
                                    data-toggle="modal" data-target="#comment"
                                    onclick="msgCommit('{{msg.id}}')">评论</button>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <ul class="list-group list-group-flush" id="{{msg.id}}">
                            {% for cmot in msg.comments %}
                            <li class="list-group-item">
                                <blockquote class="blockquote mb-0">
                                    <p>{{cmot.content}}</p>
                                    <footer class="blockquote-footer">
                                        <cite title="Source Title">{{cmot.comUserName}}</cite>&nbsp;&nbsp;对
                                        <cite title="Source Title">{{msg.msgUserName}}</cite>&nbsp;&nbsp;说
                                    </footer>
                                </blockquote>
                            </li>
                            {% endfor %}
                        </ul>

                    </div>
                </div>

                {% endfor %}

            </div>
            <div class="col-sm">
            </div>
        </div>
    </div>


    <!-- 发表说说  -->
    <div class="modal fade" id="saysomething" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">发表说说</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <input type="text" class="form-control" aria-describedby="passwordHelpInline" name="msgSay"
                                id="msgSay">
                            <!-- <small id="passwordHelpInline" class="text-muted">
                            Must be 8-20 characters long.
                          </small> -->
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="say()">发表</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 评论一下 -->
    <div class="modal fade" id="comment" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">评论一下</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <input type="text" class="form-control" aria-describedby="passwordHelpInline"
                                id="commentText">
                           
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal"
                        onclick="saveComment()">发表</button>
                </div>
            </div>
        </div>
    </div>


<!-- 回到顶部 与 底部 -->
    <div class="top gongyong">
        <a href="javascript:void(0);">顶部</a>
    </div>
    <div class="bottom gongyong">
        <a href="javascript:void(0);">底部</a>
    </div>

<!-- 备案号 -->
<div style="position:fixed; bottom:15px; width:100%; text-align:center;"a href="http://beian.miit.gov.cn">
    <div><a href="http://beian.miit.gov.cn" class="icp" > 皖ICP备2020018722号</a></p>
    </div>
    <img width="20" height="20" src="/imgs/备案图标.png" style="margin-right: 260px;">
    <div style="position:fixed; bottom:0px; width:100%; text-align:center; color:rgb(76, 76, 218)"><a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11010502030143"> 闽公网安备 35058102000233号</a></p>
       
    </div>
        </div>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/time.js"></script>
    <script> clickEffect(); //调用事件函数</script>
    <script>
        let currentMsgId = '';
        function logout() {
            $.ajax({
                url: "/logout",
                type: "POST",
                dataType: "json",
                success: function (res) {
                    console.log(res);
                    if (res.code === 200) {
                        window.location.href = "/login";
                    }
                },
                error: function (msg) {
                    console.log('网络或者服务器有问题');
                }
            })
        }
        function say() {
            let data = {
                msgSay: $('#msgSay').val()
            }
            $.ajax({
                url: "/say",
                type: "POST",
                dataType: "json",
                data: data,
                success: function (res) {
                    console.log(res);
                    if (res.code === 200) {
                        let data = JSON.parse(res.data);
                        console.log(data);
                        let html = `
                        <div class="card border-primary shadow" style="width: 50rem;">
                            <div class="card-header">
                                <div class="row">
                                    <div class="col-sm-10">${data.content}</div>
                                    <div class="col-sm-2"><button type="button" class="btn btn-secondary btn-sm"
                                            data-toggle="modal" data-target="#comment"
                                            onclick="msgCommit(${data.id})">评论一下</button>
                                    </div>
                                </div>

                            </div>
                            <div class="card-body">
                                <ul class="list-group list-group-flush" id="${data.id}">
                                   
                                </ul>

                            </div>
                        </div>
                        `;



                        $("#saysayMsg").prepend(html);
                        // window.location.href="/login";
                    }
                },
                error: function (msg) {
                    console.log('网络或者服务器有问题');
                }
            })
        }
        function msgCommit(msgId) {
            currentMsgId = msgId;
        }
        function saveComment() {

            let data = {
                msgId: currentMsgId,
                content: $('#commentText').val()
            }
            $.ajax({
                url: "/comment",
                type: "POST",
                dataType: "json",
                data: data,
                success: function (res) {
                    console.log(res);
                    if (res.code === 200) {
                        let data=res.data;
                        console.log(data);
                        let html=`
                            <li class="list-group-item">
                                <blockquote class="blockquote mb-0">
                                    <p>${data.content}</p>
                                    <footer class="blockquote-footer">
                                        <cite title="Source Title">${data.fromUserName}</cite>&nbsp;&nbsp;对
                                        <cite title="Source Title">${data.toUserName}</cite>&nbsp;&nbsp;说
                                    </footer>
                                </blockquote>
                            </li>
                        `;





                        $("#" + currentMsgId).append(html);
                        // window.location.href="/login";
                    }
                },
                error: function (msg) {
                    console.log('网络或者服务器有问题');
                }
            });
        }
        //点击按钮返回顶部
	$('#backUp').click(
	      function () {
	        $('html,body').animate({
	          scrollTop: '0px'
	        },200);//200毫秒返回到顶部
	        return false;
	      });
	      //按钮的显示隐藏
	    window.onscroll = function () {
	      if (document.documentElement.scrollTop + document.body.scrollTop > 100) {
	        document.getElementById("backUp").style.display = "block";//backUp是取得id
	      }
	      else {
	        document.getElementById("backUp").style.display = "none";
	      }
	    }
            //回到 顶部 和回到 底部
        $(function() {
    $(window).scroll(function() {
        if ($(window).scrollTop() >= 300) {
            $('.gongyong a').fadeIn(600);
        } else {
            $('.gongyong a').fadeOut(600);
        }
    });
    $('.gongyong a').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
    $('.top a').click(function() {
        $("html,body").animate({
            scrollTop: 0
        }, 500);
    });
    $('.bottom a').click(function() {
        $("html,body").animate({
            scrollTop: $(document).height()
        }, 500);
    });
});
    </script>

</body>

</html>